package example;

import java.awt.Color;
import java.awt.Dimension;

import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * This is a sample visualizer plugin that implements the
 * VisualizerPluginInterface
 * 
 */
public class SampleVisualizerPlugin implements
		framework.VisualizerPluginInterface {
	// Preferred dimensions of cell
	private final static int xsize = 5;
	private final static int ysize = 5;

	
	/**
	 * Given a panel and a state, this method draws the visualization of the
	 * cell on the panel window. This plugin draws a cell as a filled square.
	 * 
	 * @param JPanel pane - the pane on which the cell is drawn
	 * @param int state - the cell's state
	 */
	@Override
	public void drawCell(JPanel pane, int state) {
		// If the state is an even number, represent cell as a
		// white square, otherwise, a black square.
		Color c = (state % 2 == 0) ? Color.white : Color.black;
		// Use a colored JLabel to represent the cell
		JLabel jl = new JLabel(" ");
		jl.setBackground(c);
		jl.setPreferredSize(new Dimension(xsize, ysize));
		jl.setOpaque(true);
		pane.add(jl);
	}

	
	/**
	 * Returns dimensions of cell visualization
	 * 
	 * @return Dimension d - the preferred dimension of the cell
	 */
	@Override
	public Dimension getPreferredDimension() {
		return new Dimension(xsize, ysize);
	}

	
	/**
	 * Returns array of all colors that represent all possible states of a cell.
	 * 
	 * @return Color[] colors - all the colors corresponding to each states
	 */
	@Override
	public Color[] getStateColors() {
		// Cells are either white or black
		Color[] colors = { Color.white, Color.black, };
		return colors;
	}
}
